package com.tsysytems.gui;

import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tsystems.protocol.client.ClientPassenger;

public class TicketViewPanel extends JPanel {

	TicketTable ticketsTable = new TicketTable();
	private static final long serialVersionUID = 6489712085149821505L;

	Logger logger = LoggerFactory.getLogger(getClass());

	public TicketViewPanel() {
		super(new GridBagLayout());

		setBorder(new TitledBorder("Мои билеты"));

		ticketsTable.updateTable(ClientPassenger.getInstance().viewTickets());
		ticketsTable.setSelectListener(new ListSelectionListener() {
			
			public void valueChanged(ListSelectionEvent e) {
				
				
			}
		});

		add(new JScrollPane(ticketsTable), new GridBagConstraints(0, 0, 1, 1,
				1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 0), 0, 0));
	/*	add(createButtonPanel(), new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(-5, 0, 0, 0), 0, 0));*/

	}

	public JPanel createButtonPanel() {

		JPanel result = new JPanel(new FlowLayout());
		JButton removeTicket = new JButton("Удалить билет");
		removeTicket.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				

			}
		});
		result.add(removeTicket);
		return result;
	}

	public void updateTable() {

		ticketsTable.updateTable(ClientPassenger.getInstance().viewTickets());
	}
}
